#include <keyboard.h>
#include <vga.h>

int (*key_handlers[MAX_KEYBOARD_HANDLERS]) (unsigned char);
int cant_handlers;

void keyboard_handler(char key) {

	unsigned int i;

	//recorro los handlers registrados y les envio las teclas
	for (i = 0; i < cant_handlers; i++) {
		key_handlers[i](key);
	}
}

int keyboard_register(int (*f)(unsigned char)) {

	//si no habia mas lugar para registrar handlers retorno un error
	if (MAX_KEYBOARD_HANDLERS == cant_handlers) {
		return KEYBOARD_NO_HANDLERS_FREE;
	}

	key_handlers[cant_handlers] = f;
	cant_handlers++;

	return KEYBOARD_OK; 
}

void keyboard_init() {

	cant_handlers = 0;

}
